//用户详情
import 'package:flutter/material.dart';
import 'package:test_xzkdemo/utils/common/global.dart';

//列表页面示例
class UserInfoPage extends StatefulWidget {
  UserInfoPage({Key key, String title}) : super(key: key);

  @override
  _UserInfoPageState createState() => new _UserInfoPageState();
}

class _UserInfoPageState extends State<UserInfoPage> {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: AppBar(
        centerTitle: true,
        title: Text("我的"),
      ),
      body: Container(
        width: G.screenWidth(context),
        child: Column(
          children: <Widget>[
            buildItem("账号","123456"),
            buildItem("姓名","123456"),
            buildItem("性别","123456"),
            buildItem("地区","123456"),
            buildItem("爱好","123456"),
          ],
        ),
      ),
    );
  }
 

//构建复用的工具行
  Widget buildItem(String title, String msg) {
    Text titleText = Text(
      title,
      style: TextStyle(
        color: Colors.black,
        fontSize: 14,
      ),
    );

    Text msgText = Text(
      msg,
      style: TextStyle(
        color: Colors.grey[600],
        fontSize: 13,
      ),
    );
    Divider line = Divider(
      height: 1,
      color: Colors.grey[300],
    );

    GestureDetector clickMsg=GestureDetector(
      child: msgText,
      onTap: ()=>_showEdtDialog(msg),
    );
//居左居右 采用的是 row + container + alignment来实现的
   Row body = Row(
      children: <Widget>[
        Container(
          margin: EdgeInsets.only(top:10,left: 12),
          width: G.screenWidth(context)/2-12,
          alignment: Alignment.centerLeft,
          child: titleText,
        ),
        Container(
          margin: EdgeInsets.only(top:10,right: 12),
          alignment: Alignment.centerRight,
          child: clickMsg,
          width: G.screenWidth(context)/2-12,
        ),
      ],
    );

    return Column(
      children: <Widget>[
        body,
        Container(
          margin: EdgeInsets.only(top:10,left: 12),
          child: line,
        ),
      ],
    );
  }

  TextEditingController msgEdt= TextEditingController();
//包含编辑功能
  void _showEdtDialog(String phone){
    msgEdt.text = phone;
    showDialog(
        context: context,
        barrierDismissible: false,
        builder: (BuildContext context) {
          return AlertDialog(
            title: Text('提示'),
            content: TextField(controller: msgEdt,),
            actions: <Widget>[
              FlatButton(
                onPressed: () => Navigator.of(context).pop(),
                child: Text('取消'),
              ),
              FlatButton(
                onPressed: (){
                  print("确定");
                  Navigator.of(context).pop();
                },
                textColor: Colors.blue,
                child: Text('确定'),
              ),
            ],
          );
        });
  }
}
